package com.bo.entity;

import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import android.content.res.XmlResourceParser;
import android.util.Xml;
import com.bo.util.LoadResourceProxy;

public class CompanyTouch {
    
	private String id;
	private String name;
	private String webSite;
	private String email;
	private String phone;
	private String fax;
	private String address;
	private double longitude;
	private double latitude;
	private String image;	
	
	
    public CompanyTouch(String id) {
		super();
		this.id = id;
	}


	public CompanyTouch createCompanyTouch(String companyId) throws Exception{
		
	   CompanyTouch cpt=new CompanyTouch(companyId);

	   String xmlStr=LoadResourceProxy.getXMLString(LoadResourceProxy.COMPANY_TOUCH,companyId);
		
	   XmlPullParser xrp=Xml.newPullParser();

		if(xmlStr==null){
			
			throw new Exception("appear error");
		}
		
		StringReader reader=new StringReader(xmlStr);
		
		xrp.setInput(reader);
	    
	    boolean isCompanyTouch=false;
		
		while(xrp.getEventType()!=XmlResourceParser.END_DOCUMENT){
				
		  if(xrp.getEventType()==XmlResourceParser.START_TAG){
					
		       String tagName=xrp.getName();
		       
			   if(tagName.equalsIgnoreCase("CompanyTouch")){
						
				   isCompanyTouch=true;
				       
			   }else if(tagName.equalsIgnoreCase("id")&&isCompanyTouch){
				   
				   cpt.setId(xrp.nextText());
				   
			   }else if(tagName.equalsIgnoreCase("name")&&isCompanyTouch){
				   	
				   cpt.setName(xrp.nextText());
				
			   }else if(tagName.equalsIgnoreCase("webSite")&&isCompanyTouch){
				   	
				   cpt.setWebSite(xrp.nextText());
			   
			   }else if(tagName.equalsIgnoreCase("email")&&isCompanyTouch){
				   	
				   cpt.setEmail(xrp.nextText());

			   }else if(tagName.equalsIgnoreCase("phone")&&isCompanyTouch){
				   
				   cpt.setPhone(xrp.nextText());
			   
			   }else if(tagName.equalsIgnoreCase("fax")&&isCompanyTouch){
				   
				   cpt.setFax(xrp.nextText());
			   
			   }else if(tagName.equalsIgnoreCase("image")&&isCompanyTouch){
				   
				   cpt.setImage(xrp.nextText());
			   
			   }else if(tagName.equalsIgnoreCase("address")&&isCompanyTouch){
				   
				   cpt.setLatitude(Double.valueOf(xrp.getAttributeValue(null, "latitude")));
				   
				   cpt.setLongitude(Double.valueOf(xrp.getAttributeValue(null, "longitude")));
				   
				   cpt.setAddress(xrp.nextText());

			   }

		   }else if(xrp.getEventType()==XmlResourceParser.END_TAG){
			   
			   String tagName=xrp.getName();
			   
			   if(tagName.equalsIgnoreCase("CompanyTouch")){
					
				   isCompanyTouch=false;    
				   
				   break;
			   }
		   }
				
			xrp.next();
		}

		return cpt;
    }
	

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getWebSite() {
		return webSite;
	}
	public void setWebSite(String webSite) {
		this.webSite = webSite;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getFax() {
		return fax;
	}
	public void setFax(String fax) {
		this.fax = fax;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public double getLongitude() {
		return longitude;
	}
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}
	public double getLatitude() {
		return latitude;
	}
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}

	
}
